//
//  UILabel+LabelHeight.m
//  Arts1
//
//  Created by Mac Jc on 15/10/6.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "UILabel+LabelHeight.h"

@implementation UILabel (LabelHeight)


// 定义成方法方便多个label调用 增加代码的复用性
+ (CGFloat)heightWithString:(NSString *)string theWidth:(float)width font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 0)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    CGFloat result = rect.size.height;
    return result;
}


+ (void)setLineSpacingWithLabel:(UILabel *)label withLineSpacing:(float)lineSpacing
{
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:lineSpacing];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [label.text length])];
    [label setAttributedText:attributedString1];
    [label sizeToFit];
}






@end
